﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Chapter08
{
    using Chapter08.View;

    /// <summary>
    /// 第8章 元素绑定
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            #region 01 将元素绑定到一起
            /*
             * 01 绑定元素表达式
             * 02 绑定错误
             * 03 绑定模式
             * 04 使用代码创建绑定
             * 05 使用代码检索绑定
             * 06 多绑定
             * 07 绑定更新
             * 08 绑定延迟
             * */
            #endregion

            #region 02 绑定到非元素对象
            /*
             * 01 Source 属性
             * 02 RelativeSource 属性
             * 03 DataContext 属性
             * */
            #endregion

            #region 03 小结
            #endregion
        }

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Open)
            {
                var button = e.Source as Button;
                if (button != null)
                {
                    if (button == button1)
                    {
                        Demo(new ElementToElementBindingWindow());
                    }
                    if (button == button2)
                    {
                        Demo(new MultipleBindingsWindow());
                    }
                }
            }
        }

        private void Demo(Window window)
        {
            window.Owner = this;
            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            window.ShowDialog();
        }
    }
}
